'use strict';

const wechat = require('wechat')
const app = require('../app')
const textMessage = require('./textMessage')
const eventMessage = require('./event')
const WECHAT_CONFIG = require('./config')

const api = require('./wechatAPI')

app.use('/wechat', wechat(WECHAT_CONFIG, function (req, res, next) {
  var data = req.weixin
  res.send('success')
  switch (data.MsgType) {
    case 'text':
      textMessage(data, api)
      break
    case 'event':
      eventMessage(data, api)
      break
    default:
      api.sendText(data.FromUserName, '不能识别', new Function)
      break
  }

}))

module.exports = api
